import { isEmptyObject } from "../../../utils/utils";
import {request} from '../../../utils/http'

const app = getApp();

interface IConfirmIndexPage {
  staffInfo?: Staff.IStaffItem;
  resDetailData?: {};
  resDetailKeys?: {}[];
  formData?: {}[];
}

interface IConfirmIndexMethods {
  saveFormRef?(data): void;
}

Page<any, IConfirmIndexMethods, any>({
  data: {
    resDetailKeys: [
      { key: "date", label: "预约时间" },
      { key: "serviceNameDesc", label: "预约项目" },
      { key: "serviceTimDesc", label: "预约时长", desc: "分钟" }
    ],
    formDetailKeys: [{
      key: "customName",
      label: "客户姓名",
    },{
      key: "customMobile",
      label: "手机号",
    },],
    id:'',
    info:{},
    resDetailData: {},
    formData: [
      {
        key: "customName",
        label: "客户姓名",
        require: true,
        placeholder: "姓名(必填)"
      },
      {
        key: "customMobile",
        label: "手机号",
        require: true,
        type: "number",
        isMobile: true,
        placeholder: "手机号(必填)"
      },
      {
        key: "customNum",
        label: "到店人数",
        require: true,
        type: "number",
        placeholder: "人数(必填)"
      },
      {
        key: "subscribeRemarks",
        label: "备注",
        require: false,
        placeholder: "请输入备注 "
      }
    ]
  },
  onLoad(query:any) {
    this.setData({
      id:query.id
    }, () => {
      this.getDetail()
    })
  },
  getDetail(){
    request(`/appointment/order_detail/${this.data.id}`, 'get', {
      id:this.data.id
    }).then((res:any) => {
      if (res.code == 200) {
        this.setData({
          info:res.data,
          resDetailData:{
            date:res.data.appoint_at,
            serviceNameDesc: res.data.project.name,
            serviceTimDesc: res.data.project.duration,
            customName: res.data.member.name,
            customMobile: res.data.member.mobile
          }
        })
      }
    })
  },
  cancel(){
    request(`/appointment/order_cancel/${this.data.id}`, 'post', {
      id:this.data.id
    }).then((res:any) => {
      if (res.code == 200) {
        my.showToast({content: '取消预约成功'});

        my.navigateTo({
          url:'/pages/reservation/cancel/index?status=70'
        })
        // this.getDetail()
      }
    })
  }
});
